import Heap from "../09_堆结构Heap/06_堆结构Heap(二叉堆)";

class PriorityNode<T> {
  priority: number;
  value: T;

  constructor(value: T, priority: number) {
    this.value = value;
    this.priority = priority;
  }

  valueOf(): number {
    return this.priority;
  }
}

class PriorityQueue<T> {
  private heap: Heap<PriorityNode<T>> = new Heap<PriorityNode<T>>();
  enqueue(value: T, priority: number): void {
    const newNode = new PriorityNode<T>(value, priority);
    this.heap.insert(newNode);
  }
  dequeue(): T | null {
    return this.heap.extract()?.value || null;
  }
  peek(): T | null {
    return this.heap.peek()?.value || null;
  }
  isEmpty(): boolean {
    return this.heap.isEmpty();
  }
  get size(): number {
    return this.heap.length;
  }
  print(): void {
    this.heap.print();
  }
}

const queue = new PriorityQueue<string>();
queue.enqueue("jame", 88);
queue.enqueue("tom", 100);
queue.enqueue("lucy", 60);
while (!queue.isEmpty()) {
  console.log(queue.dequeue());
}

export {};
